﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmetic.DataEntity;

namespace Cosmetic.Logic
{
	/// <summary>
	/// Product series manager class
	/// </summary>
	public class ProductSeriesManager : LogicBase
    {
		private ProductManager m_ProductManager		= new ProductManager();

		/// <summary>
		/// Insert a new ProductSeries into database
		/// </summary>
		/// <param name="aProductSeries">new ProductSeries</param>
		public void Insert(ProductSeries aProductSeries)
		{
			m_CosmeticDC.ProductSeries.InsertOnSubmit(aProductSeries);
			m_CosmeticDC.SubmitChanges();
		}

		/// <summary>
		/// Delete ProductSeries
		/// </summary>
		/// <param name="aProductSeries">The ProductSeries want delete</param>
		public void Delete(ProductSeries aProductSeries)
		{
			List<Product> theProductList	= aProductSeries.Products.ToList();
			foreach (Product theProduct in theProductList)
			{
				this.m_ProductManager.Delete(theProduct);
			}

			m_CosmeticDC.ProductSeries.DeleteOnSubmit(aProductSeries);
			m_CosmeticDC.SubmitChanges();
		}





		/// <summary>
		/// Get ProductSeries by ProductSeries Id
		/// </summary>
		/// <param name="aProductSeriesId">ProductSeries Id</param>
		/// <returns>ProductSeries</returns>
		public ProductSeries GetProductSeriesById(Guid aProductSeriesId)
		{
			return m_CosmeticDC.ProductSeries.Single(theProductSeries => theProductSeries.ProductSeriesId == aProductSeriesId);
		}

		/// <summary>
		/// get product series by brand
		/// </summary>
		/// <param name="aBrand">brand</param>
		/// <returns>product series</returns>
		public List<ProductSeries> GetProductSeriesByBrand(Brand aBrand)
		{
			return this.GetProductSeriesByBrand(aBrand.BrandId);
		}
		/// <summary>
		/// get product series by brand id
		/// </summary>
		/// <param name="aBrandId">brand id</param>
		/// <returns>product series</returns>
		public List<ProductSeries> GetProductSeriesByBrand(Guid aBrandId)
		{
			return (from theSeries in m_CosmeticDC.ProductSeries
				   where theSeries.BrandId == aBrandId
				   select theSeries).ToList();
		}

	}
}
